<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>腾飞健康管理平台</title>
    <link rel="stylesheet" href="lib/layui/css/layui.css">
</head>
<body style="padding: 10px">
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">序号</label>
        <div class="layui-input-block">
            <input type="text" name="numericalOrder" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">代码</label>
        <div class="layui-input-block">
            <input type="text" name="codeName" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="clauseName" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">参考值</label>
        <div class="layui-input-block">
            <input type="text" name="referenceValue" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单位</label>
        <div class="layui-input-block">
            <input type="text" name="units" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <input name="examineItemId" type="hidden" value="">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="submitClause">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script type="text/javascript" src="lib/layui/layui.js"></script>
<script>
    layui.use(["form", "layer", "jquery"], function () {
        let form = layui.form;
        let layer = layui.layer;
        let $ = layui.jquery;

        //获取实验室检查项目列表
        function getLabExamineItems() {
            $.ajax({
                url: "/getLabExamineItems",
                type: "post",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                async: true,
                success: function (responseData) {
                    console.log(responseData);
                    for (let i = 0; i < responseData.length; i++) {
                        $("select[name=examineItemId]").append("<option value=" + responseData[i].examineItemId + ">" + responseData[i].itemName + "</option>")
                    }
                    form.render("select");
                },
                error: function () {
                    console.log("第一个下拉框的信息(项目所属科室）请求失败。");
                }
            });
        }

        $("document").ready(getLabExamineItems());

        //form表单提交数据
        form.on("submit(submitClause)", function (data) {
            $.ajax({
                url: "/submitLabExamineClause",
                data: data.field,
                dataType: "json",
                tyep: "post",
                success: function (responseResult) {
                    let iconNum;
                    if (responseResult.code == 1) {
                        iconNum = 1;
                    } else {
                        iconNum = 2;
                    }
                    layer.msg(responseResult.msg, {
                        time: 1500,
                        icon: iconNum,
                    });
                },
                error: function () {
                    layer.msg("服务器错误！", {
                        icon: 2,
                        time: 1500,
                    });
                }
            });
            return false;
        });

        //获取父页面传递的参数
        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r !== null)
                return unescape(r[2]);
            return null;
        };

        $(document).ready(function () {
            $("input[name=examineItemId]").val(getQueryString("examineItemId"));
        });
    });
</script>
</body>
</html>